/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package foxmob.mlts.model;

import foxmob.mlts.component.StringManager;
import java.util.*;

/**
 *
 * @author Emmanouil Samatas
 */
public class Question {
    private String questionText;
    private String ID;
    private int weight;
    
    public enum QuestionType {
        MULTIPLE_CHOICE, FILL_IN_THE_BLANK, MULTIPLE_FILL_IN_THE_BLANK;
    }
   
    public Question() {
       
       UUID questionId = UUID.randomUUID();
       ID = questionId.toString();
       weight = 1;  
    }
    
    
    @Override
    public String toString() {
        return StringManager.ellipsize(questionText, 40);
    }
    
    public String getID() {
        return ID;
    }
    public void setID(String id){
        this.ID = id;
    }
    public void setQuestionText(String question) {
        questionText = question;
    }
    
    public String getQuestionText() {
        return questionText;
    }
    
    public static Class classFromQuestionType(QuestionType questionType) {
        if (questionType == QuestionType.FILL_IN_THE_BLANK) {
            return FillInTheBlanksQuestion.class;
        } else if (questionType == QuestionType.MULTIPLE_CHOICE) {
            return MultipleChoiceQuestion.class;
        } else if (questionType == QuestionType.MULTIPLE_FILL_IN_THE_BLANK) {
            return MultipleFillInBlankQuestion.class;
        }
        return null;
    }
    
    
    public void setWeight(int weight) {
        this.weight = weight;
    }
    
    public int getWeight() {
        return weight;
    }
     @Override
    public boolean equals(Object obj)
    {
         boolean isEqual = false;
        if (this.getClass() == obj.getClass())
        {
            Question myQuestion = (Question) obj;
            isEqual=(myQuestion.questionText.equals(this.questionText) && myQuestion.ID.equals(this.ID))?true:false; 
        }
 
        return isEqual;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 17 * hash + (this.questionText != null ? this.questionText.hashCode() : 0);
        hash = 17 * hash + (this.ID != null ? this.ID.hashCode() : 0);
        hash = 17 * hash + this.weight;
        return hash;
    }

}
